/**
  CNOK project, Anyang Normal University, IMP-CAS
  \class TAHist
  \brief a local histogram class for ROOT TH1F class. But as this class only
  serves for TAConvolve's random sampling, it does not have a visualization
  function.
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2022/12/03
  \date Last modified: 2022/12/03 by SUN Yazhou
  \copyright 2020-2023 SUN Yazhou
  \copyright CNOK project, Anyang Normal University, IMP-CAS
*/

#ifndef _TAHist_h_
#define _TAHist_h_

#include <map>
#include <string>

using std::map;
using std::string;

template<class T>
class TAHist{
public:
  TAHist(const string &name, const string &title, int nbins, double xmin, double xmax);
  virtual ~TAHist();

  const char *GetName() const{ return fName.c_str(); }
  const char *GetTitle() const{ return fTitle.c_str(); }

  void Fill(double v); ///< fill the histogram
  /// \param i: bin id, starts from 1, ends at fNBins
  T GetBinContent(int i) const;
  /// \param i: bin id, starts from 1, ends at fNBins
  double GetBinCenter(int i) const;
  void Scale(double v);
  /// By default the integral is computed as the sum of bin contents
  /// in the range. if option "width" is specified, the integral is
  /// the sum of the bin contents multiplied by the bin width in x.
  double Integral(const string &opt = "") const;
  void Print() const; ///< print in a terminal in ascii characters
  void Draw(const string &) const{ return Print(); }

protected:
  string fName, fTitle;
  map<int, T> fMap; // [binNo,cnt]: 0-> underflow, n+1: overflow
  int fNBins; // number of bins
  double fMin, fMax, fdx; // histogram range and step
};


typedef TAHist<double> TAH1D;
typedef TAHist<int> TAH1I;

#include "TAHist.hpp"

#endif
